<template>
  <el-select v-model="category" class="m-2" placeholder="请选择分类">
    <el-option v-for="item in cateList" :key="item" :label="item" :value="item" />
  </el-select>
  <el-button type="primary" @click="handleSearch">查询</el-button>
  <el-table :data="proList" height="80vh" style="width: 100%">
    <el-table-column label="角色ID">
      <template #default="scope">
        {{ scope.row.objectId }}
      </template>
    </el-table-column>
    <el-table-column label="商品名称">
      <template #default="scope">
        {{ scope.row.proname }}
      </template>
    </el-table-column>
    <el-table-column label="商品图片">
      <template #default="scope">
        <img :src="scope.row.img1" style="height: 30px" alt="" srcset="" />
      </template>
    </el-table-column>
    <el-table-column label="分类">
      <template #default="scope">
        {{ scope.row.category }}
      </template>
    </el-table-column>
    <el-table-column label="价格">
      <template #default="scope">
        {{ scope.row.originprice }}
      </template>
    </el-table-column>
    <el-table-column label="折扣">
      <template #default="scope">
        {{ scope.row.discount }}
      </template>
    </el-table-column>
    <el-table-column label="销量">
      <template #default="scope">
        {{ scope.row.sales }}
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import request from '../../untils/request';
import { backEnd } from '../../api/product'
export default {
  data() {
    return {
      proList: [],
      cateList: ["手机", "家电", "图书", "汽车"],
      category: "",
    };
  },
  created() {
    request.get('/classes/VueProduct').then(res => {
      this.proList = res.data.results;
    })
  },
  methods: {
    handleSearch() {
      backEnd({ category: this.category }).then(res => {
        this.proList = res.data.results
        console.log(this.proList)
      })
      console.log(this.category)
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
